import { actionTypes } from '../store'
import axios from 'axios'
import { fromJS } from 'immutable'

const getInitHomeDataAction = (data)=>{
    return {
        type: actionTypes.INIT_HOME_DATA,
        data
    }
}

const addMoreArc = (list, arcPage) =>({
    type: actionTypes.ADD_MORE_ARC,
    list: fromJS(list),
    nextPage : arcPage+1
})

export const getMouseEnterAction = (value)=>{
    return{
        type: actionTypes.CHANGE_IMG_SHOW,
        value
    }
}

export const getHomeData = ()=>{
    return (dispatch)=>{
        axios.get('/api/home.json').then((res)=>{
            const data=res.data
            if(data.success){
                dispatch(getInitHomeDataAction(fromJS(data.data)))
            }
            console.log(data)
        }).catch((error)=>{
            console.log(error)
        })
    }
}
export const loadMoreArc = (currArcPage) => {
    return (dispatch)=>{
        axios.get('/api/homeList.json?page=' + (currArcPage+1) ).then((res)=>{
            if(res.data.success){
                dispatch(addMoreArc(res.data.data, currArcPage))
            }
        })
    }
}
export const changeBackTopShowAction = (status) => ({
    type: actionTypes.CHANGE_BACK_TOP_SHOW,
    status
})
